import Vue from 'vue'
import Router from 'vue-router'

const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error => error)
}

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/login',
      name: 'login',
      component: resolve => require(['@/view/login/Login'], resolve)
    },
    {
      path: '/',
      name: 'index',
      component: resolve => require(['@/view/Index'], resolve),
      children: [
        {
          path: 'manage',
          name: 'manage',
          component: require('@/view/manage/Manage').default,
          children: [
            {
              path: 'org',
              name: 'org',
              component: require('@/view/manage/org/Org').default,
              children: []
            },
            {
              path: 'user',
              name: 'user',
              component: require('@/view/manage/user/User').default,
              children: []
            },
            {
              path: 'role',
              name: 'role',
              component: require('@/view/manage/role/Role').default,
              children: []
            },
            {
              path: 'menu',
              name: 'menu',
              component: require('@/view/manage/menu/Menu').default,
              children: []
            },
            {
              path: 'permission',
              name: 'permission',
              component: require('@/view/manage/permission/Permission').default,
              children: []
            },
            {
              path: 'session',
              name: 'session',
              component: require('@/view/manage/session/Session').default,
              children: []
            },
            {
              path: 'notice',
              name: 'notice',
              component: require('@/view/manage/notice/Notice').default,
              children: []
            },
            {
              path: 'dict',
              name: 'dict',
              component: require('@/view/manage/dict/Dict').default,
              children: []
            },
            {
              path: 'deploy',
              name: 'deploy',
              component: require('@/view/manage/deploy/Deploy').default,
              children: []
            },
            {
              path: 'email',
              name: 'email',
              component: require('@/view/manage/email/Email').default,
              children: [
                {
                  path: 'template',
                  name: 'template',
                  component: resolve => require(['@/view/manage/email/template/Template'], resolve),
                  children: []
                }
              ]
            },
            {
              path: 'cloud',
              name: 'cloud',
              component: resolve => require(['@/view/manage/cloud/Cloud'], resolve),
              children: [
                {
                  path: 'service',
                  name: 'service',
                  component: resolve => require(['@/view/manage/cloud/service/Service'], resolve),
                  children: []
                }
              ]
            }
          ]
        },
        {
          path: 'monitor',
          name: 'monitor',
          component: resolve => require(['@/view/monitor/Monitor'], resolve),
          children: [
            {
              path: 'complete',
              name: 'complete',
              component: resolve => require(['@/view/monitor/complete/Complete'], resolve),
              children: [
                {
                  path: 'alternate',
                  name: 'alternate',
                  component: resolve => require(['@/view/monitor/complete/alternate/Alternate'], resolve),
                  children: []
                },
                {
                  path: 'surplus',
                  name: 'surplus',
                  component: resolve => require(['@/view/monitor/complete/surplus/Surplus'], resolve),
                  children: []
                }
              ]
            },
            {
              path: 'server',
              name: 'server',
              component: resolve => require(['@/view/monitor/server/Server'], resolve),
              children: []
            },
            {
              path: 'database',
              name: 'database',
              component: resolve => require(['@/view/monitor/database/Database'], resolve),
              children: []
            },
            {
              path: 'product',
              name: 'product',
              component: resolve => require(['@/view/monitor/product/Product'], resolve),
              children: []
            }
          ]
        }
      ]
    },
    {
      path: '*',
      redirect: '/'
    }
  ]
})
